package com.example.a14110100420.yuejian.WAdapter.personal;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a14110100420.yuejian.R;
import com.example.a14110100420.yuejian.Wbase.Conast;
import com.example.a14110100420.yuejian.Wbean.personal.MyOrder;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by wanger on 2017/11/10.
 */

public class MyDingdanListAdapter extends RecyclerView.Adapter {
    private List<MyOrder> userDingdan;
    private Context context;
    private LayoutInflater layoutInflater;
    public MyDingdanListAdapter(Context context, List<MyOrder> userDingdan){
        this.context=context;
        this.userDingdan=userDingdan;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView=LayoutInflater.from(context).inflate(R.layout.myorder_adapter,parent,false);
        MyOrderViewHolder holder = new MyOrderViewHolder(itemView);

        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyOrderViewHolder myOrderViewHolder = (MyOrderViewHolder) holder;
        MyOrder dingdan = userDingdan.get(position);
        String id=dingdan.getId();
        String state=dingdan.getVstate();
        String pic= Conast.base_picUrl+dingdan.getThumb();
        String name=dingdan.getName();
        String price=dingdan.getPrice();
        String time=dingdan.getUpdate_time();
        String pay=dingdan.getPay();

        myOrderViewHolder.dingdan_id.setText(id);
        if (dingdan.getVstate().equals("0")){
            myOrderViewHolder.dingdan_state.setText("未参加");
        }else if (dingdan.getVstate().equals("1")){
            myOrderViewHolder.dingdan_state.setText("已参加");
        }else if (dingdan.getVstate().equals("3")){
            myOrderViewHolder.dingdan_state.setText("申请退款");
        }else {
            myOrderViewHolder.dingdan_state.setText("已退款");
        }
        myOrderViewHolder.dingdan_name.setText(name);
        myOrderViewHolder.dingdan_price.setText(price);
        myOrderViewHolder.dingdan_time.setText(time);
        myOrderViewHolder.dingdan_pay.setText(pay);
        Picasso.with(context).load(pic).into(myOrderViewHolder.dingdan_pic);
        if (dingdan.getType().equals("2")){
            myOrderViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                }
            });
           }

    }

    @Override
    public int getItemCount() {
        return userDingdan.size();
    }
    public class MyOrderViewHolder extends RecyclerView.ViewHolder{

        public TextView dingdan_id;
        public TextView dingdan_state;
        public TextView dingdan_name;
        public TextView dingdan_price;
        public TextView dingdan_time;
        public TextView dingdan_pay;
        public ImageView dingdan_pic;
        public View itemView;

        public MyOrderViewHolder(View itemView) {
            super(itemView);
            this.itemView=itemView;
            dingdan_id=  itemView.findViewById(R.id.user_dingdan_id);
            dingdan_state=  itemView.findViewById(R.id.user_dingdan_state);
            dingdan_name=  itemView.findViewById(R.id.user_dingdan_name);
            dingdan_price=  itemView.findViewById(R.id.user_dingdan_price);
            dingdan_time=  itemView.findViewById(R.id.user_dingdan_time);
            dingdan_pay=  itemView.findViewById(R.id.user_dingdan_pay);
            dingdan_pic=  itemView.findViewById(R.id.user_dingdan_pic);
        }
    }
}
